package com.systop.busafter.comment.controller;

import com.systop.busafter.comment.service.CommentService;
import com.systop.commer.ResponseResult;
import com.systop.commer.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CommentController {
    @Autowired
    private CommentService commentService;

    //添加
    @RequestMapping(value="/insertcomment",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult insertcomment(@RequestBody Comment comment){
        int i =  commentService.insertcomment(comment);
        if (i == 0) {
            return ResponseResult.build(500, "添加失败");
        } else {
            return ResponseResult.build(200, "添加成功", i);
        }
    }

    //查看全部
    @RequestMapping(value="/commentListall",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentListall(){
        List<Comment> list =  commentService.commentListall();
        if (list == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);
        }
    }

    //通过id查  list
    @RequestMapping(value="/commentIdlist",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentIdlist(@RequestParam(value = "comment_id")int comment_id){
        List<Comment> list =  commentService.commentIdlist(comment_id);
        if (list == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);
        }
    }
    //通过id查  实体类
    @RequestMapping(value="/CommentId",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult CommentId(@RequestParam(value = "comment_id")int comment_id){
       Comment l =  commentService.CommentId(comment_id);
        if (l == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", l);
        }
    }
    //删除
    @RequestMapping(value="/deletecomment",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult deletecomment(@RequestParam(value = "comment_id")int comment_id){
       int i =  commentService.deletecomment(comment_id);
        if (i == 0) {
            return ResponseResult.build(500, "删除失败");
        } else {
            return ResponseResult.build(200, "删除成功", i);
        }
    }

    //用用户id查看
    @RequestMapping(value="/commentuseridall",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentuseridall(@RequestParam(value = "comment_user_id")int comment_user_id){
        List<Comment> l =  commentService.commentuseridall(comment_user_id);
        if (l == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", l);
        }
    }

    //用司机id查看
    @RequestMapping(value="/commentdriveridall",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentdriveridall(@RequestParam(value = "comment_driver_id")int comment_driver_id){
        List<Comment> l =  commentService.commentdriveridall(comment_driver_id);
        if (l == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", l);
        }
    }

    //通过评论分数 和 用户id查
    @RequestMapping(value="/commentuserfraction",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentuserfraction(@RequestBody Comment comment){
        List<Comment> list =  commentService.commentuserfraction(comment);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功", list);
        }
    }
    //通过评论分数 和 用户id查
    @RequestMapping(value="/commentdriverfraction",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult commentdriverfraction(@RequestBody Comment comment){
        List<Comment> list =  commentService.commentdriverfraction(comment);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功", list);
        }
    }

}
